﻿using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using TrackSystem.EmailService;

namespace TrackSystem.API.Extensions
{
    /// <summary>
    /// 注册邮件服务
    /// </summary>
    public static class EmailServiceExtension
    {
        /// <summary>
        /// 邮件注册函数
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        public static void AddEmailService(this IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<FromEmailConfig>(configuration);
            services.AddScoped<IEmailSender, EmailSender>();
        }
    }

    /// <summary>
    /// 电子邮件确认令牌提供程序
    /// </summary>
    /// <typeparam name="TUser"></typeparam>
    public class EmailConfirmationTokenProvider<TUser> : DataProtectorTokenProvider<TUser> where TUser : class
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataProtectionProvider"></param>
        /// <param name="options"></param>
        /// <param name="logger"></param>
        public EmailConfirmationTokenProvider(
            IDataProtectionProvider dataProtectionProvider, 
            IOptions<DataProtectionTokenProviderOptions> options, 
            ILogger<DataProtectorTokenProvider<TUser>> logger) : base(dataProtectionProvider, options, logger)
        {
        }
    }

    /// <summary>
    /// 新的选项类，用于配置电子邮件确认令牌提供程序
    /// </summary>
    public class EmailConfirmationTokenProviderOptions : DataProtectionTokenProviderOptions
    {
    }
}
